package student.aistar.day11;

import student.aistar.day10.Book;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

public class ComparatorFactory {
    public static final int ISBN = 0;
    public static final int PRICE = 1;

    public static Comparator<Book> getInstance(int index){
        Comparator<Book> c = null;
        switch (index){
            case PRICE:
                c = (o1, o2) -> (int) (o1.getPrice() - o2.getPrice());
                break;
            case ISBN:
                c = (o1, o2) -> o1.getIsbn().compareTo(o2.getIsbn());
                break;
        }
        return c;
    }
}
class TestFactory{
    public static void main(String[] args) {
        Book b1 = new Book(1,"1001","java",100.0d);
        Book b2 = new Book(2,"1002","java",200.0d);
        Book b3 = new Book(3,"1003","java",200.0d);
        Book b4 = new Book(4,"1004","python",300.0d);

        List<Book> bookList = new ArrayList<>();
        bookList.add(b1);
        bookList.add(b2);
        bookList.add(b3);
        bookList.add(b4);

        bookList.sort(ComparatorFactory.getInstance(1));
        System.out.println(bookList);
    }
}